package com.leyou.controller;

import com.leyou.ResponseData;
import com.leyou.entity.SpecParam;
import com.leyou.service.SpecParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/spec/param")
public class SpecParamController {

    @Autowired
    private SpecParamService specParamService;

    @GetMapping("/{gid}")
    public ResponseData getSpecParamByGroupId(@PathVariable Long gid) {
        try {
            if (gid > 0) {
                List<SpecParam> specParams = specParamService.getSpecParamByGroupId(gid);
                return ResponseData.ok(specParams);
            } else {
                return ResponseData.error(400, "groudId,请求参数有误!", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.error(500, "服务器繁忙", null);
    }
}
